package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SysProject;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysAdminProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wux
 * @date 2023/5/12 14:51
 */
@Api(tags = "(运营端) 用户项目管理")
@RestController
@RequestMapping("/admin/project")
public class SysAdminProjectController {
    @Autowired
    private ISysAdminProjectService sysAdminProjectService;

    @PostMapping("/add")
    @Log(title = "新增运营端项目", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增用户项目",response = SysProject.class)
    public ResultEntity add(@RequestBody SysProject params){
        //检查项目名是否存在
        SysProject entity = new SysProject();
        entity.setProjectName(params.getProjectName());
        entity.setCreateBy(SecurityUtils.getLoginUser().getUser().getId());
        entity.setUpdateBy(SecurityUtils.getLoginUser().getUser().getId());
        sysAdminProjectService.save(entity);
        return ResultEntity.createSuccess(entity);
    }
    @PostMapping("/update")
    @Log(title = "修改运营端项目状态", businessType = BusinessType.INSERT)
    @ApiOperation(value = "修改项目状态",response = SysProject.class)
    public ResultEntity update(@RequestBody SysProject params){
        //检查项目名是否存在
        params.setUpdateBy(SecurityUtils.getLoginUser().getUser().getId());
        sysAdminProjectService.updateById(params);
        return ResultEntity.createSuccess();
    }

    @GetMapping("/list/{userId}")
    @ApiOperation(value = "查询用户项目列表",response = SysProject.class)
    public ResultEntity listByUser(@PathVariable("userId") Long userId){
        return ResultEntity.createSuccess(sysAdminProjectService.getProjectByUser(userId));
    }

}
